<?php

namespace App\Models\Collection;

class CollectionFilesModel extends BaseCollectionModel
{
    protected $table = 'collection_files';

    /**
     * 根据藏品id标记删除
     *
     * @param int $collectionId
     * @return mixed
     */
    public function deleteItemByCollectionId(int $collectionId)
    {
        return $this->where('collection_id', $collectionId)
            ->where('deleted', self::DELETED_NO)
            ->update([
                'deleted' => self::DELETED_YES,
            ]);
    }

    /**
     * 根据藏品ids标记删除
     *
     * @param array $collectionIds
     * @return mixed
     */
    public function deleteItemByCollectionIds(array $collectionIds)
    {
        return $this->whereIn('collection_id', $collectionIds)
            ->where('deleted', self::DELETED_NO)
            ->update([
                'deleted' => self::DELETED_YES,
            ]);
    }

    /**
     * 藏品文件列表
     *
     * @param int   $collectionId
     * @param array $fields
     * @return mixed
     */
    public function getListByCollectionId(int $collectionId, array $fields = self::QUERY_DEFAULT_FIELDS)
    {
        return $this->select($fields)
            ->where('collection_id', $collectionId)
            ->where('deleted', self::DELETED_NO)
            ->get()
            ->toArray();
    }
}
